package com.yigang.controller;

import java.text.ParseException;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yigang.entity.ActivitySession;
import com.yigang.service.ActivitySessionService;
import com.yigang.utils.ResultUtil;

/**
 * @author 陈佳祥
 *活动场次   管理
 */
@Controller
@RequestMapping("/activitySession")
public class ActivitySessionController {
	
	@Autowired
	private ActivitySessionService activitySessionService;//注入service层
	//增删改查方法
		@RequestMapping("activitySessionList")
		public String activitySessionList() {
			return "jsp/activitySession/activitySessionList";
		}
		@RequestMapping("addActivitySession")
		public String addActivitySession() {
			return "jsp/activitySession/addActivitySession";
		}
		
		@RequestMapping("editActivitySession/{session_id}")
		public String editActivitySession(@PathVariable("session_id") int session_id, HttpSession session) {
			ActivitySession activitySession = activitySessionService.selectActivitySessionById(session_id);
		
			session.setAttribute("activitySession", activitySession);
			return "jsp/activitySession/editActivitySession";
		}
		
		//添加活动场次
		@RequestMapping("insertActivitySession")
		@ResponseBody
		public ResultUtil insertActivitySession(ActivitySession record) {
			activitySessionService.insertSelective(record);
			return ResultUtil.ok();

		}
			//根据id删除
		@RequestMapping("deleteActivitySessionById")
		@ResponseBody
		public ResultUtil deleteActivitySessionById(int session_id) {
			
			return activitySessionService.deleteByPrimaryKey(session_id);
		}
			//获取所有的活动  带分页功能
		@RequestMapping("getActivitySessionList")
		@ResponseBody
		public ResultUtil getActivitySessionList(Integer page, Integer limit, ActivitySession record) {

			return activitySessionService.selectActivitySessionList(page, limit, record);
		}
			//更新活动
		@RequestMapping("updateActivitySession")
		@ResponseBody
		public ResultUtil updateActivitySession(ActivitySession record) throws ParseException {
			
			return activitySessionService.updateByPrimaryKeySelective(record);
		}
		//修改当前活动状态   根据id修改   是否开启活动
		@RequestMapping("updateActivitySessionStatusById")
		@ResponseBody
		public ResultUtil updateActivitySessionStatusById(int session_id, int session_status) {
			return activitySessionService.updateActivitySessionStatusById(session_id, session_status);
		}
}
